-- =====================================================================
-- 
--   File:      setup.sql
--   Summary:   This file contains the TSQL to support the ODBC_filestream sample.
--  
--   Date:      December 4, 2007
-- 
-- ---------------------------------------------------------------------
-- 
--   This file is part of the Microsoft SQL Server Code Samples.
--   Copyright (C) Microsoft Corporation.  All rights reserved.
-- 
-- This source code is intended only as a supplement to Microsoft
-- Development Tools and/or on-line documentation.  See these other
-- materials for detailed information regarding Microsoft code samples.
-- 
-- THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF 
-- ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
-- PARTICULAR PURPOSE.
-- 
-- ===================================================================== 

USE master
GO

-- enable file stream
EXEC sp_filestream_configure 3
GO

-- create directory for filestream database
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
EXEC xp_cmdshell 'md c:\filestreamdemo'
GO

-- Drop the filestream demo database
IF EXISTS (SELECT name FROM master..sysdatabases WHERE name = 'myfilestreamdb')
    DROP DATABASE [myfilestreamdb]
GO

-- Create filestream demo database
CREATE DATABASE [myfilestreamdb] ON PRIMARY
    (NAME=[myfilestreamdbprimary], FILENAME='c:\filestreamdemo\dbf.mdf'),
    FILEGROUP [fsgrp] CONTAINS FILESTREAM (NAME=[fscnt],FILENAME='c:\filestreamdemo\fscnt')
    LOG ON (NAME=[dblog], FILENAME='c:\filestreamdemo\db1.ldf', SIZE=5MB, MAXSIZE=3000MB, FILEGROWTH=5MB)
GO

-- Create table that contain filestream column
CREATE TABLE [myfilestreamdb]..[mydocs]
(
    id UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL UNIQUE,
    doc VARBINARY(MAX) FILESTREAM
)
GO
